// 水质数据API
import { get, getSilent, post, put, del } from './request.js'

export const fetchRealtimeWaterQuality = () => {
  return get('/api/water-quality/realtime')
}

// 获取实时水质数据
export const getRealtimeData = (deviceId) => {
  return get('/water-quality/realtime', { deviceId })
}

// 从 Redis 获取某设备最新一条水质数据（后端需提供该接口）
export const getLatestRedisData = (deviceId) => {
  // 约定接口：GET /device/latest?deviceId=xxx
  // 返回形如 { code:200, data:{ ph, temp, ntu, status, latitude, longitude, timestamp } }
  return getSilent('/device/latest', { deviceId })
}

// 获取历史水质数据
export const getHistoryData = (params) => {
  return get('/water-quality/history', params)
}

// 获取水质统计数据
export const getStatisticsData = (params) => {
  return get('/water-quality/statistics', params)
}

// 获取水质异常数据
export const getAnomalyData = (params) => {
  return get('/water-quality/anomaly', params)
}

// 处理水质异常
export const handleAnomaly = (anomalyId, data) => {
  return put(`/water-quality/anomaly/${anomalyId}/handle`, data)
}

// 获取水质报告
export const getWaterQualityReport = (params) => {
  return get('/water-quality/report', params)
}

// 获取水质标准
export const getWaterQualityStandard = () => {
  return get('/water-quality/standard')
}

// 获取水质评估
export const getWaterQualityAssessment = (params) => {
  return get('/water-quality/assessment', params)
}
